package com.bysj.service.impl;

import java.util.ArrayList;

import com.bysj.dao.NewsDao;
import com.bysj.dao.impl.NewsDaoImpl;
import com.bysj.entity.News;
import com.bysj.service.NewsService;

public class NewsServiceImpl implements NewsService{
	private NewsDao nd=new NewsDaoImpl();
	@Override
	public void addNews(News news) {
		String sql="insert into news(title,content,time,pic,author,source,editor) values(?,?,?,?,?,?,?)";
		nd.addNews(sql, news);
	}

	@Override
	public void delNews(News news) {
		String sql="delete from news where id= ?";
		nd.delNews(sql, news);
	}

	@Override
	public void updateNews(News news) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public News queryNews(News news) {
		String sql="select id,title,content,time,pic,author,source,editor from news where id= ?";
		return nd.queryNews(sql, news);
	}

	@Override
	public int CountNews() {
		String sql="select COUNT(*) from news";
		return nd.CountAllNews(sql);
	}

	@Override
	public ArrayList<News> queryAllNews() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public ArrayList<News> FenyeQuery(int page, int rows) {
		String sql="select id,title,content,time,pic,author,source,editor from news limit ?,?";
		return nd.FenyeQuery(sql, page, rows);
	}

	@Override
	public ArrayList<News> queryZuiXinNews() {
		String sql="select id,title,content,time,pic,author,source,editor from news limit 1,10";
		return nd.queryhotNews(sql);
	}

	@Override
	public void updatepicById(News news) {
	String sql="update news set pic=? where id=?";
		nd.updatePicById(sql,news);
	}

	@Override
	public int CountAllNewsBytitle(News news) {
		String sql="select count(*) from news where title like '%"+news.getTitle()+"%'";
		return nd.CountAllNews(sql);
	}

	@Override
	public int CountAllNewsBycontent(News news) {
		String sql="select count(*) from news where content like '%"+news.getContent()+"%'";
		return nd.CountAllNews(sql);
	}

	@Override
	public int CountAllNewsBytime(News news) {
		String sql="select count(*) from news where time like '%"+news.getTime()+"%'";
		return nd.CountAllNews(sql);
	}

	@Override
	public int countAllNewsById(News news) {
		String sql="select count(*) from news where id like '%"+news.getId()+"%'";
		return nd.CountAllNews(sql);
	}

	@Override
	public ArrayList<News> FenyeQueryBytitle(int nowPage, int pageRowNum,
			News news) {
		String sql="select id,title,content,time,pic,author,"
				+ "source,editor from news where title like '%"+news.getTitle()+"%' limit ?,?";
		return nd.FenyeQuery(sql, nowPage, pageRowNum);
	}

	@Override
	public ArrayList<News> FenyeQueryByContent(int nowPage, int pageRowNum,
			News news) {
		String sql="select id,title,content,time,pic,author,"
				+ "source,editor from news where content like '%"+news.getContent()+"%' limit ?,?";
		return nd.FenyeQuery(sql, nowPage, pageRowNum);
	}

	@Override
	public ArrayList<News> FenyeQueryByTime(int nowPage, int pageRowNum,
			News news) {
		String sql="select id,title,content,time,pic,author,"
				+ "source,editor from news where time like '%"+news.getTime()+"%' limit ?,?";
		return nd.FenyeQuery(sql, nowPage, pageRowNum);
	}

	@Override
	public ArrayList<News> FenyeQueryById(int nowPage, int pageRowNum, News news) {
		String sql="select id,title,content,time,pic,author,"
				+ "source,editor from news where id like '%"+news.getId()+"%' limit ?,?";
		return nd.FenyeQuery(sql, nowPage, pageRowNum);
	}

}
